package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceSaveParam;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Tag(name="电子围栏模块")
@RequestMapping("/v1/geofence/")
public class GeofenceController {
    @Autowired
    GeofenceService geofenceService;

    @GetMapping("select")
    @Operation(summary = "查询电子围栏")
    @ApiOperationSupport(order = 10)
    public JsonResult selectGeofence(GeofenceQuery geofenceQuery){
        log.debug("查询电子围栏:geofenceQuery={}",geofenceQuery);
        List<GeofenceVO> list=geofenceService.selectGeofence(geofenceQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    @Operation(summary = "新增电子围栏")
    @ApiOperationSupport(order = 20)
    public JsonResult saveGeofence(@Validated GeofenceSaveParam geofenceSaveParam){
        log.debug("新增电子围栏:geofenceParam={}",geofenceSaveParam);
        geofenceService.saveGeofence(geofenceSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("update/{id}/{status}")
    @Operation(summary = "修改电子围栏状态")
    @ApiOperationSupport(order = 30)
    public JsonResult updateGeofenceStatus(@PathVariable Long id, @PathVariable String  status){
        log.debug("修改电子围栏状态:id={},status={}",id,status);
        geofenceService.updateStatus(id,status);
        return JsonResult.ok();
    }

    @PostMapping("unbind/{vehicleId}")
    @Operation(summary = "解绑电子围栏")
    @ApiOperationSupport(order = 40)
    public JsonResult unbindVehicle(@PathVariable Long vehicleId){
        log.debug("解绑电子围栏:vehicleId={}",vehicleId);
        geofenceService.unbindVehicle(vehicleId);
        return JsonResult.ok();
    }
}
